package com.nuoniu.sibanyun.controller.cms;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.cms.CmsTemplate;
import com.nuoniu.sibanyun.service.cms.ICmsTemplateService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 网站模版管理 前端控制器
 * </p>
 *
 * @author 小网站模版管理e啊刚
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/cms/template")
@Api(tags = "网站模版管理")
public class CmsTemplateController extends BaseController {

    @Autowired
    private ICmsTemplateService templateService;

    @ApiOperation("获取模版列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, CmsTemplate template) {
        return HttpResult.ok(templateService.pageList(page, template));
    }

    @ApiOperation("保存模版")
    @PostMapping("save")
    public HttpResult save(@RequestBody CmsTemplate template) {
        template.setCompanyId(UserThreadLocal.get().getCompanyId());
        templateService.saveOrUpdate(template);
        return HttpResult.ok();
    }

    @ApiOperation("删除模版")
    @PostMapping("delete")
    public HttpResult delete(Long id) {
        templateService.removeById(id);
        return HttpResult.ok();
    }

    @ApiOperation("使用模版")
    @GetMapping("useTemplate")
    public HttpResult useTemplate(Integer id) {
        templateService.useTemplate(id);
        return HttpResult.ok();
    }
}
